home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
WANDR401.ZIP
/
sources
/
solu-io.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-08-24
|
2KB
|
92 lines
/* solu-io.c */
/* Functions for recording the solution */
#include "wand_head.h"
extern int debug_disp;
extern char *edit_screen;
extern char lscreen[NOOFROWS][ROWLEN+1];
extern char *edit_memory;
extern char *memory_end;
extern char screen_name[61];
extern char *screenpath;
/* save and restore edit memory data */
edit_save(num)
int num;
{
char file[90];
int i = 0, fd;
char *c;
if (num>0)
sprintf(file,"%s/solu/path.%d",screenpath,num);
else
save_soln_file_name(file);
if ((fd = open(file,O_WRONLY|O_CREAT|O_TRUNC,0644)) == -1)
alert_message("File cannot be opened for writing.");
else {
/*
i = write(fd, edit_memory, (int)(memory_end - edit_memory));
*/
for (c=edit_memory;c<memory_end;c++)
if(*c== 'j' || *c == 'k' || *c == 'l' || *c == 'h'
|| *c == ')' || *c == ' ') write(fd,c,1);
// if (i < 0) alert_message("Write error on file.");
close(fd);
}
}
int edit_restore(num)
int num;
{
char file[90];
int i = 0, fd;
if (num>0)
sprintf(file,"%s/solu/path.%d",screenpath,num);
else
load_soln_file_name(file);
if ((fd = open(file,O_RDONLY)) == -1)
{
if(num<0)
alert_message("File cannot be opened for reading.");
else
alert_message("No solution file available yet.");
return -1;
}
else {
for (i=0;i<EMSIZE;i++) edit_memory[i]=0;
i = read(fd, edit_memory, EMSIZE);
if (i < 0) alert_message("Read error on file.");
if (i == 0) alert_message("File empty.");
if (i > 0) {
sprintf(file,"Read in %d moves.",i);
notify_message(file);
edit_memory[i] = ')';
memory_end = edit_memory + i;
}
close(fd);
}
return 0;
}
int size_of_path_file(num)
int num;
{
long size;
char file[90];
sprintf(file,"%s/solu/path.%d",screenpath,num);
size = file_size(file);
return size;
}